package com.lc.demo.mapper;


import com.lc.demo.bean.Classgrade;
import com.lc.demo.bean.Student;
import com.lc.demo.bean.Subject;
import com.lc.demo.bean.Teacher;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SubjectMapper {

    @Insert("insert into subject (name,term,teacherId,departmentid,departmentname) values (#{name},#{term},#{teacherId},#{departmentid},#{departmentname})")
    void add(Subject subject);

    @Select(" select * from subject where departmentid =#{departmentid}")
    List<Subject> getSubjectList(@Param("departmentid") Integer departmentid);

    @Update("update subject set name=#{name},term=#{term},teacherId=#{teacherId} ,departmentid=#{departmentid} ,departmentname=#{departmentname} where id=#{id}")
    void updateSubject(Subject subject);

    @Delete("delete from subject where id=#{id}")
    void delSubject(Subject subject);

     @Select("select * from subject where subname=#{subname}")
     Subject selectSubjectByName(@Param("subname") String subname);

    @Select("select id  from subject where name =#{name}")
    Integer selectIdByName(@Param("name") String name);
    @Insert("insert into grade_course  values (#{classId},#{subjectId})")
    void insertGradeCourse(@Param("classId") Integer classId, @Param("subjectId") Integer subjectId);

    @Delete("delete from grade_course where  courseid =#{id} ")
    void deleteGradeSubject(@Param("id") Integer id);


    @Select("select t1.* from  grade_course t2 left join classgrade t1 on t2.classgradeid =t1.id  where t2.courseid=#{subjectId}")
    List<Classgrade> findClassListBySubjectId(@Param("subjectId") Integer subjectId);


    @Select("select   * from  student where classid =#{classId}")
    List<Student> findStudentListByClassId(@Param("classId") Integer classId);

    @Select("select * from teacher where username =#{username}")
    Teacher findTeacherByUsername(String username);

    @Select("select  * from  subject where teacherId=#{id}")
    List<Subject> findSubjectListByTeacherId(@Param("id") Integer id);
    @Select("select  * from  subject where id=#{subId}")
    Subject subJectById(@Param("subId") Integer subId);
}
